#coding:utf-8
"""
*   Coder : Dzlua
*   Email : 505544956@qq.com
*   Time  : 2017/08/28
"""

#---------------------------#

import MySQLdb

#---------------------------#
class Cursor:
    def __init__(self, cursor):
        self.__cursor = cursor
    def execute(self):
        self.__cursor.execute()
    def fetchone(self):
        '''返回获取下一个查询结果集,结果集是一个对象'''
        return self.__cursor.fetchone()
    def fetchall(self):
        '''返回接收全部的返回结果行'''
        return self.__cursor.fetchall()
    def rowcount():
        '''返回执行execute()方法后影响的行数'''
        return self.__cursor.rowcount
#---------------------------#
class Connect:
    def __init__(self, conn):
        self.__conn = conn
    def close(self):
        self.__conn.close()
    def cursor(self):
        cursor = self.__conn.cursor()
        return Cursor(cursor)
    def commit(self):
        self.__conn.commit()
    def rollback(self):
        self.__conn.rollback()
#---------------------------#
class DataBase:
    def connect(self, host, db, user, pwd):
        conn = MySQLdb.connect(host=host,db=db,user=user,passwd=pwd,charset="utf8")
        return Connect(conn)
#---------------------------#
